/* Created by Anjuta version 1.2.4a */
/*	This file will not be overwritten */


//todo: x logic checking
//todo:   timeout if data does not arrive
//todo: x  code seperation, multiple files

#include <_G_config.h>

#include <signal.h>
#include <gtkmm.h>
#include <libglademm.h>

#include <chat_server.h>



char* program_path;
void catch_sig(int sig_num){
	printf("signal %d caught\n", sig_num);
	fflush(stdout);
	
	sigset_t mask_set;	/* used to set a signal masking set. */
	sigset_t old_set;	/* used to store the old mask set.   */
	/* mask any further signals while we're inside the handler. */
	sigfillset(&mask_set);
	sigprocmask(SIG_SETMASK, &mask_set, &old_set);
	
	switch(sig_num){
		case 6:
		case 11:
			pid_t pid=fork();
			if(pid==0){
				if(execl(program_path, program_path, (char*)0)==-1){
                    printf("error spawning replacement process\n");
					exit(0);
                }
				return;
			}
			else{
				exit(0);
			}
	}
}
int main(int argc, char **argv){
	//this will *probably* work, given the shell provides it and no one is spoofing
	program_path=argv[0];
	//set signal handler to catch errors
	//signal(SIGSEGV, catch_sig);
	//signal(SIGABRT, catch_sig);
	
	if(!Glib::thread_supported()) Glib::thread_init();
	gdk_threads_enter();
	Gtk::Main kit(argc, argv);
	
	ChatServer chat_server;

	g_debug("Finished creating splash_screen");
	chat_server.run();
	gdk_threads_leave();
	return 0;
}
//aaronds109:S34MLJky - Password for dreamhost - Naaaaak for info
